#include "stringutil.h"

/*---------------------------------------------------------------------------*/
string nonprint(unsigned char const &c)
/*---------------------------------------------------------------------------*/
{
	string s = ""; s.append(1,c);
	return nonprint(s);
}
/*---------------------------------------------------------------------------*/


/*---------------------------------------------------------------------------*/
string nonprint(const string &s)
/*---------------------------------------------------------------------------*/
{
	string r;

	for(unsigned i=0; i<s.length(); i++)
		if(s[i] < 32) switch(s[i]) {
		case '\r': r.append("\\r"); break;
		case '\n': r.append("\\n"); break;
		default:   r.append("\\?");
		}
	else
		if(s[i]=='\\') r.append("\\\\");
		else r.append(1,s[i]);

	return r;
}
/*---------------------------------------------------------------------------*/


/*---------------------------------------------------------------------------*/
string operator+(const string &s, const int &i)
/*---------------------------------------------------------------------------*/
{
	stringstream ss;

	ss << s << i;

	return ss.str();
}
/*---------------------------------------------------------------------------*/


/*---------------------------------------------------------------------------*/
string operator+(const string &s, const unsigned &i)
/*---------------------------------------------------------------------------*/
{
	stringstream ss;

	ss << s << i;

	return ss.str();
}
/*---------------------------------------------------------------------------*/


/*---------------------------------------------------------------------------*/
string operator+(const string &s, const double &d)
/*---------------------------------------------------------------------------*/
{
	stringstream ss;

	ss << s << d;

	return ss.str();
}
/*---------------------------------------------------------------------------*/


/*---------------------------------------------------------------------------*/
string operator+(const string &s, const char *c)
/*---------------------------------------------------------------------------*/
{
	stringstream ss;

	ss << s << c;

	return ss.str();
}
/*---------------------------------------------------------------------------*/


/*---------------------------------------------------------------------------*/
string hex(u_int32_t i)
/*---------------------------------------------------------------------------*/
{
	stringstream ss;

	ss << hex << i;

	return ss.str();
}
/*---------------------------------------------------------------------------*/
